package com.example.dmdomain.entity;


import com.example.dmcommom.Enum.ElectricityCategoryEnum;
import com.example.dmcommom.Enum.ElectricityTimeCategoryEnum;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Calendar;

/**
 * 电网分时记录
 *
 * @author yym
 */
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@NoArgsConstructor
@Table(name = "electricity_time_division")
public class ElectricityTimeSlot implements Serializable {

	@Id
	private String id;

	/**
	 * 省
	 */
	@Column(name = "province")
	private String province;

	/**
	 * 市
	 */
	@Column(name = "city")
	private String city;

	/**
	 * 用电类型1：两部制、单一制
	 */
	@Column(name = "electricity_category")
	private ElectricityCategoryEnum electricityCategory;

	/**
	 * 用电类型2：工商业、大工业
	 */
	@Column(name = "type")
	private String type;

	/**
	 * 电压
	 */
	@Column(name = "voltage")
	private String voltage;

	/**
	 * 时段分类：尖、峰、平、谷、深谷
	 */
	@Column(name = "time_category")
	private ElectricityTimeCategoryEnum timeCategory;


	/**
	 * 月份
	 */
	@Column(name = "year")
	private Integer year;

	/**
	 * 月份
	 */
	@Column(name = "mon")
	private Integer month;

	/**
	 * 时段开始时间
	 */
	@Column(name = "start_time")
	private Calendar startTime;

	/**
	 * 时段结束时间
	 */
	@Column(name = "end_time")
	private Calendar endTime;

	public ElectricityTimeSlot deepClone() {
		return SerializationUtils.clone(this);
	}

	public String getUid(int id) {
		return province + "_" + city + "_" + electricityCategory + "_" + timeCategory + "_" + year + "_" + month + "_" + id;
	}

	@Override
	public String toString() {
		return "ElectricityTimeSlot{" +
				", province='" + province + '\'' +
				", city='" + city + '\'' +
				", electricityCategory=" + electricityCategory +
				", timeCategory=" + timeCategory +
				", month=" + month +
				", startDate=" + startTime.get(Calendar.HOUR_OF_DAY) + ":" + startTime.get(Calendar.MINUTE) +
				", endDate=" + endTime.get(Calendar.HOUR_OF_DAY) + ":" + endTime.get(Calendar.MINUTE) +
				'}';
	}
}
